<template>
    <div class="content-wrapper">
      <!-- Content Header (Page header) -->
      <section class="content-header">
        <h1>
          客户管理
        </h1>

        <ol class="breadcrumb">
          <li><a href="#"> 控制台</a></li>
          <li><a href="#">客户信息</a></li>
          <li class="active">编辑</li>
        </ol>
      </section>

      <!-- Main content -->
      <section class="content">
          <div class="row">
            <div class="col-xs-12">
                <div class="box box-solid">
                  <div class="box-header with-border">
                    <h3 class="box-title">编辑客户信息</h3>
                  </div>
                  <!-- /.box-header -->
                  <!-- form start -->
                  <form class="form-horizontal">
                    <div class="box-body">
                        <div class="pull-right" style="margin-right:60px;">
                            <p><i class="fa fa-user"></i> 基本信息</p>
                        </div>
                        <div style="clear:both;"></div>


                      <div class="row">
                          <div :class="['form-group','col-sm-6',{'has-error':errors.has('name')}]">
                            <label class="col-sm-2 control-label">客户名称</label>
                            <div class="col-sm-10">
                              <input v-validate="'required|max:30'" class="form-control" name="name" placeholder="30个字" v-model="model.name">
                              <span class="help-block" v-if="errors.has('name')">{{errors.first('name')}}</span>
                            </div>
                          </div>

                          <div :class="['form-group','col-sm-6',{'has-error':errors.has('custom_type')}]">
                            <label class="col-sm-2 control-label">等级</label>
                            <div class="col-sm-10">
                              <select class="form-control" v-model="model.custom_type" v-validate="'required|min_value:1'" name="custom_type">
                                  <option value="0">请选择</option>
                                  <option v-for="basedata in custom_type_list" :value="basedata.id">{{basedata.value}}</option>
                              </select>
                              <span class="help-block" v-if="errors.has('custom_type')">{{errors.first('custom_type')}}</span>
                            </div>
                          </div>
                      </div>



                      <div class="row">
                          <div :class="['form-group','col-sm-6',{'has-error':errors.has('region_id')}]">
                            <label  class="col-sm-2 control-label">地区</label>
                            <div class="col-sm-10">
                              <select class="form-control" v-model="model.region_id" v-validate="'required|min_value:1'" name="region_id">
                                  <option value="0">请选择</option>
                                  <option value="1">北京</option>
                                  <option value="2">上海</option>
                                  <option value="3">广州</option>
                              </select>
                              <span class="help-block" v-if="errors.has('region_id')">{{errors.first('region_id')}}</span>
                            </div>
                          </div>
                          <div class="form-group col-sm-6">
                              <label  class="col-sm-2 control-label">详细地址</label>
                              <div class="col-sm-10">
                                  <input class="form-control" placeholder="" v-model="model.address">
                              </div>
                          </div>
                      </div>

                      <div class="row">
                          <div :class="['form-group','col-sm-6',{'has-error':errors.has('happy')}]">
                              <label class="col-sm-2 control-label">满意度</label>
                              <div class="col-sm-10">
                                <select class="form-control" v-model="model.happy" v-validate="'required'" name="happy">
                                    <option value="1">1星</option>
                                    <option value="2">2星</option>
                                    <option value="3">3星</option>
                                    <option value="4">4星</option>
                                    <option value="5">5星</option>
                                </select>
                                <span class="help-block" v-if="errors.has('happy')">{{errors.first('happy')}}</span>
                              </div>
                          </div>
                          <div :class="['form-group','col-sm-6',{'has-error':errors.has('credit')}]">
                              <label class="col-sm-2 control-label">信用度</label>
                              <div class="col-sm-10">
                                <select class="form-control" v-model="model.credit" v-validate="'required'" name="credit">
                                    <option value="1">1星</option>
                                    <option value="2">2星</option>
                                    <option value="3">3星</option>
                                    <option value="4">4星</option>
                                    <option value="5">5星</option>
                                </select>
                                <span class="help-block" v-if="errors.has('credit')">{{errors.first('credit')}}</span>
                              </div>
                          </div>
                      </div>

                      <div class="row">
                          <div :class="['form-group','col-sm-6',{'has-error':errors.has('user_id')}]">
                              <label  class="col-sm-2 control-label">客户经理</label>
                              <div class="col-sm-10">
                                <select class="form-control" v-model="model.user_id" v-validate="'required'" name="user_id">
                                    <option v-for="user in user_list" :value="user.id">{{user.name}}</option>
                                </select>
                                <span class="help-block" v-if="errors.has('user_id')">{{errors.first('user_id')}}</span>
                              </div>
                          </div>
                          <div :class="['form-group','col-sm-6',{'has-error':errors.has('status')}]">
                              <label class="col-sm-2 control-label">状态</label>
                              <div class="col-sm-10">
                                  <select class="form-control" v-model="model.status" v-validate="'required'" name="status">
                                      <option value="0">正常</option>
                                      <option value="1">已流失</option>
                                  </select>
                                  <span class="help-block" v-if="errors.has('status')">{{errors.first('status')}}</span>
                              </div>
                          </div>
                      </div>




                      <div class="pull-right" style="margin-right:60px;">
                          <p><i class="fa fa-phone"></i> 联系方式</p>
                      </div>
                      <div style="clear:both;"></div>
                      <div class="row">
                          <div :class="['form-group','col-sm-6',{'has-error':errors.has('phone')}]">
                              <label class="col-sm-2 control-label">联系电话</label>
                              <div class="col-sm-10">
                                  <input class="form-control" placeholder="固话或手机号码" v-model="model.phone" v-validate="'required'" name="phone">
                                  <span class="help-block" v-if="errors.has('phone')">{{errors.first('phone')}}</span>
                              </div>
                          </div>
                          <div class="form-group col-sm-6">
                              <label class="col-sm-2 control-label">传真</label>
                              <div class="col-sm-10">
                                  <input class="form-control" v-model="model.fax">
                              </div>
                          </div>
                      </div>

                      <div class="row">
                          <div class="form-group col-sm-6">
                              <label class="col-sm-2 control-label">邮编</label>
                              <div class="col-sm-10">
                                  <input class="form-control" v-model="model.zipcode">
                              </div>
                          </div>
                          <div class="form-group col-sm-6">
                              <label class="col-sm-2 control-label">网址</label>
                              <div class="col-sm-10">
                                  <input class="form-control" placeholder="http://" v-model="model.website">
                              </div>
                          </div>
                      </div>


                      <div class="pull-right" style="margin-right:60px;">
                          <p><i class="fa fa-info"></i> 其他信息</p>
                      </div>
                      <div style="clear:both;"></div>
                      <div class="row">
                          <div class="form-group col-sm-6">
                              <label class="col-sm-2 control-label">营业执照</label>
                              <div class="col-sm-10">
                                  <input class="form-control" placeholder="营业执照注册号" v-model="model.biz_licence">
                              </div>
                          </div>
                          <div class="form-group col-sm-6">
                              <label class="col-sm-2 control-label">法人</label>
                              <div class="col-sm-10">
                                  <input class="form-control" v-model="model.boss">
                              </div>
                          </div>
                      </div>

                      <div class="row">

                          <div class="form-group col-sm-6">
                              <label class="col-sm-2 control-label">注册资金</label>
                              <div class="col-sm-10">
                                  <input class="form-control" placeholder="单位:万元" v-model="model.regist_capital">
                              </div>
                          </div>
                          <div class="form-group col-sm-6">
                              <label class="col-sm-2 control-label">开户银行</label>
                              <div class="col-sm-10">
                                  <input class="form-control" v-model="model.bank_name">
                              </div>
                          </div>
                      </div>

                      <div class="row">

                          <div class="form-group col-sm-6">
                              <label class="col-sm-2 control-label">银行帐号</label>
                              <div class="col-sm-10">
                                  <input class="form-control" v-model="model.bank_no">
                              </div>
                          </div>
                      </div>
                    </div>
                    <!-- /.box-body -->
                    <div class="box-footer">
                      <button type="button" class="btn btn-primary" @click="submit">保存</button>
                    </div>
                    <!-- /.box-footer -->
                  </form>
                </div>
              <!-- /.box -->
            </div>
          </div>
      </section>
      <!-- /.content -->
    </div>
    <!-- /.content-wrapper -->
</template>

<script>
import Custom from '@/modules/Custom'
import User from '@/modules/User'
import BaseData from '@/modules/BaseData'

export default {

    mounted() {
        this.loadModel();
    },

    data() {
        return {
            model:{
                status:0,
                happy:1,
                credit:1
            },

            //客户等级列表
            custom_type_list:[],

            //客户经理列表
            user_list:[]
        };
    },

    methods: {



        loadModel() {
            if(this.$route.params.id > 0){
                Custom.show(this.$route.params.id)
                .then((response) => {
                    this.model = response.contents;
                });
            }
            User.list({role_id:User.ROLE_CUSTOM_MANAGER},false)
            .then((response) => {
                this.user_list = response.contents;
            });

            BaseData.list({cate_id:BaseData.CUSTOM_TYPE},false)
            .then((response) => {
                this.custom_type_list = response.contents;
            });
        },

        submit() {
            this.$validator.validateAll().then((result) => {
                if(!result){
                    return;
                }
                if(this.$route.params.id > 0){
                    Custom.put(this.$route.params.id,this.model)
                    .then((response) => {
                        $.message('操作成功');
                        this.$router.push({name:'CustomIndex'});
                    })
                }else{
                    Custom.store(this.model)
                    .then((response) => {
                        $.message('操作成功');
                        this.$router.push({name:'CustomIndex'});
                    });
                }
            });
        }
    },

    computed:{

    }
}
</script>

<style lang="css">
</style>
